package com.qf.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.qf.commons.TableData;
import com.qf.entity.Address;
import com.qf.mapper.AddressDao;
import com.qf.service.AddressService;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class AddressServiceImpl implements AddressService {

    private AddressDao addressDao;

    public AddressServiceImpl(AddressDao addressDao) {
        this.addressDao = addressDao;
    }

    @Override
    public TableData<Address> QueryByIdAll(Integer offset,Integer limit,Integer uId) {

        QueryWrapper<Address> aqw = new QueryWrapper<>();
        aqw.eq("u_id",uId);
        List<Address> addresses = addressDao.selectList(aqw);
        TableData<Address> tableData = new TableData<>();
        Page<Address> page = PageHelper.offsetPage(0, 10);
        if (addresses.size()>0){
            tableData.setTotal(page.getTotal());
            tableData.setRows(addresses);
        }
        return tableData;
    }
}
